package com.tanguy.user.ui.me.activity.order

import android.support.design.widget.TabLayout
import android.view.ViewGroup
import android.widget.TextView
import com.tanguy.user.R
import com.tanguy.user.base.TabLayoutActivity
import com.tanguy.user.utlis.extend.dp2px
import com.tanguy.user.utlis.extend.getColorKt
import org.jetbrains.anko.backgroundResource
import org.jetbrains.anko.find
import org.jetbrains.anko.textColor
import java.util.*

/**
 * Created by dab on 2017/10/10 0010 10:00
 * 我的订单
 */
class OrderActivity : TabLayoutActivity() {
    override fun setContentViewRes(): Int = R.layout.activity_tab_tab
    override fun getTabString(): ArrayList<String> = arrayListOf("出行订单", "酒店订单")
    val tripTabString = arrayListOf("全部", "待接单", "待服务", "服务中", "待评价", "已完成", "已取消")
    val hotelTabString = arrayListOf("全部", "待付款", "待确认", "待入住", "人住中", "待评价", "已完成", "已取消")
    val couponsAdapter by lazy {
//        CouponsAdapter()
    }
    lateinit var tabLayoutType: TabLayout
    val unusedData = arrayListOf(1, 2, 3)
    val hasUsedData = arrayListOf(10, 11, 12)
    override fun onTabItemSelected(position: Int) {
        when (position) {
            0 -> {
//                couponsAdapter.test = unusedData
                initTabLayoutType(tripTabString)
            }
            1 -> {
//                couponsAdapter.test = hasUsedData
                initTabLayoutType(hotelTabString)
            }
        }
    }

    fun resetTabLayoutType() {
        tabLayoutType.getTabAt(0)?.select()
    }

    override fun initView() {
        super.initView()
//        mRvContent.adapter = couponsAdapter
        tabLayout.setSelectedTabIndicatorColor(getColorKt(R.color.white))
        tabLayout.setTabTextColors(getColorKt(R.color.white),getColorKt(R.color.white))
    }

    override fun initEvent() {
        super.initEvent()
        tabLayoutType.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
            override fun onTabReselected(tab: TabLayout.Tab?) {

            }

            override fun onTabUnselected(tab: TabLayout.Tab?) {
                if (tab == null) return
                tab.customView?.setBackgroundResource(0)
            }

            override fun onTabSelected(tab: TabLayout.Tab?) {
                if (tab == null) return
                tab.customView?.setBackgroundResource(R.drawable.select_orange_stroke)
            }

        })
    }

    @SuppressWarnings("all")
    override fun onResume() {
        super.onResume()
        initTabLayoutType(tripTabString)
    }


    private fun initTabLayoutType(vararg: ArrayList<String>) {
        tabLayoutType = find<TabLayout>(R.id.tab_title_type).apply {
            removeAllTabs()
            vararg.map {
                val newTab = newTab()
                newTab.customView = TextView(context).apply {
                    layoutParams = ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
                    text = it
                    textColor = getColorKt(R.color.white)
                    backgroundResource = 0
                    setPadding(dp2px(10), 0, dp2px(10), 0)
                }
                addTab(newTab)
            }
        }
        resetTabLayoutType()
    }
}